<template>
    <div v-if="drawer">
      <el-drawer
        :title="subtitle"
        :visible.sync="drawer"
        direction="rtl"
        :show-close="true"
        :wrapper-closable="true"
        :append-to-body="true"
        :wrapperClosable="false"
        :before-close="handleClose"
        :size="`85%`"
      >
      
        <div class="mt14" v-if="importTemplate.widgetList.length" v-loading="formloading">
          <VFormRender
            v-if="drawer"
            ref="preForm"
            :form-json="importTemplate"
            :form-data="testFormData"
            :preview-state="true"
            :option-data="testOptionData"
            :global-dsv="designerDsv"
            :index-flag="indexflag"
          >
          </VFormRender>
          <!-- from-foot-btn fix -->
          <div class="button fixnew btn-shadow">
            <el-button size="small" class="el-btn" @click="handleClose">取消</el-button>
            <el-button size="small" type="primary" :loading="loading" @click="saveFn" v-if="testFormData.pihe !=1">保存</el-button>
          </div>
          <div class="" style="margin-top:20px;" v-if="drawer">
              <wuliaodangan ref="wulidangan" v-show="formDataAll.length > 0" :keyName="keyName" :iscopy="iscopy" :testFormData="testFormData" :id="id" :typeid="wltypeid" :isSubmit="isSubmit"  :formDataAll="formDataAll"></wuliaodangan>
            </div>
        </div>
        <div v-else>
          <default-page :index="16" :min-height="420" />
        </div>
      </el-drawer>
    </div>
  </template>
  <script>
  import VFormRender from '@/components/form-render/index'
  import defaultPage from '@/components/common/defaultPage'
  import { crudModuleCreateApi, crudModuleSaveDataApi, crudModuleUpdateApi, 
    crudModuleBatchDelApi, crudForminsertDataAllApi, crudModuleFindApi, crudModuleListApi} from '@/api/develop'
  import { FacialVerificationApi } from '@/api/enterprise'
  import { CLOSE_NODE_ICON_TOOLBAR } from '@/components/xmind-editor/event-constant'
  import ApiUrl from '@/api/apiUrls' // dengshunbo 2024-12-27新增
  import wuliaodangan from '@/components/detailsEdit/wuliaodangan.vue'
  import { EventBus } from '@/libs/bus'
  export default {
    name: '',
    components: { VFormRender, defaultPage, wuliaodangan },
    props: {
      keyName: {
        type: String,
        default: ''
      },
      crud: {
        type: Object,
        default: () => {}
      }
    },
    data() {
      return {
        drawer: false,
        isSubmit: 0,
        importTemplate: {
          formConfig: {},
          widgetList: []
        },
        title: '新增',
        id: 0, // 当前列表的id值
        designer: {},
        testFormData: {},
        loading: false,
        testOptionData: {
          select62173: [],
          select001: []
        },
        formloading: false,
        drawerData:{},
        indexflag: 1,
        wltypeid: 0,
       
        formdatasubmit:{},
        isFlage: false,
        iscopy: 0,
        subtitle: '新增',
        dataModuleInfo: {},
        formDataAll: [],

      

        formDataAll2: [
            {
                name: '物料',
                value: 'shengchandanwuliao',
                datadictname:'',
                tableHeader:[], // 表格头部信息
                tableData:[], // 表格数据
                oldData: [],
                deleteData:[], // 要删除的表格数据
                selectData:[], // 选中数据
                istable: true,
                datadictList:{},
                subitem:[
                // {
                //   name:'添加',
                //   icon: 'el-icon-plus',
                //   index: 1,
                //   value: 'add',
                //   tablename:'wuliaoxinxi'
                //   },
                  {
                  name:'选择',
                  icon: 'el-icon-plus',
                  index: 2,
                  value: 'select'
                  },
                  {
                  name:'删除',
                  icon: 'el-icon-delete',
                  index: 3,
                  value: 'delete'
                  }],
                search: {},
                form: {},
            },
            {
                name: '工艺',
                value: 'shengchandangongyi',
                datadictname:'',
                tableHeader:[], // 表格头部信息
                tableData:[], // 表格数据
                deleteData:[], // 要删除的表格数据
                selectData:[], // 选中数据
                istable: true,
                datadictList:{},
                subitem:[ {
                    name:'添加',
                    icon: 'el-icon-plus',
                    index: 1,
                    value: 'add',
                    tablename:'',
                },
                {
                    name:'删除',
                    icon: 'el-icon-delete',
                    index: 3,
                    value: 'delete'
                }],
                search: {},
                form: {}
            },
          
        ],

        formSearch: {
          page: 1,
          limit: 10,
          is_field_all: 1,
          is_system: 1,
          order_by: {},
          scope_frame: 'all',
          show_search_type: '0',
          view_search: [],
          view_search_boolean: '',

        },
        danghaoNumber: 10,// 制造单号
       
      }
    },
    computed: {
      designerDsv() {
        return this.globalDsv
      }
    },
    beforeDestroy() {
      EventBus.$off('selectinputEventbus', this.selectinputEventbus)
    },
    mounted() {
        console.log("this", this.keyName)
        if(this.keyName=='shengchandan'){ // 生产单
          this.formDataAll = this.formDataAll2;
        }
        EventBus.$on('selectinputEventbus', this.selectinputEventbus)
    }, 
    methods: {
      async openBox(id, data, status=0) { // status0 新增或编辑，1复制新增
        console.log("Module-openBox-addDrawernew:", id, data, status)
        this.iscopy = status;
        this.id = 0;
        if (id) {
          this.id = id
          this.drawerData = data; // dengshunbo 2025-3-17 获取查看详情数据
          if(data.module_info.item_sn){
            this.wltypeid = data.module_info.itemt_sn.id;
          }
          if(this.iscopy==1){
            this.subtitle = '新增复制'
          }else{
             this.subtitle = '编辑'
          }
        } else {
          this.subtitle = '新增'
          this.$set(this, 'testFormData', {})
        }
        let obj = {}
        if (this.crud) {
          obj.crud_id = this.crud.crud_id
          obj.crud_value = this.crud.crud_value
        } else {
          obj = {}
        }
        obj.id = this.id
        const res = await crudModuleCreateApi(this.keyName, obj)
        if (res.data.form_info && res.data.form_info.global_options) {
          this.$set(this.importTemplate, 'formConfig', res.data.form_info.global_options)
        }
        this.$set(this.importTemplate, 'widgetList', res.data.form_info.options)
        // dengshunbo 2025-1-20 改
        if (data) {
          // dengshunbo 2025-1-20
          if(this.keyName=="fangkeguanli"){
            if(data.module_info.shouquanmenjinzu){
               let meji = data.module_info.shouquanmenjinzu.split(",")
               data.module_info.shouquanmenjinzu = meji;
            }else{
               data.module_info.shouquanmenjinzu = ''
            }
            this.$set(this, 'testFormData', data.module_info)
          }else{
            this.$set(this, 'testFormData', data.module_info)
          }
        }
        // end
        // 原代码
        // if (data) {
        //   this.$set(this, 'testFormData', data.module_info)
        // }

        this.isSubmit = 1;
        this.drawer = true
        
      },
      handlerisSubmitVal(val){

      },
      getFormSumbit(val){
         
      },

      // 从表单组件返回的数据eventbus 数据通信
      async selectinputEventbus(data, index){
        if(index==0){ // 清除
            let formdataModel = JSON.parse(JSON.stringify(this.$refs.preForm.formDataModel));
            formdataModel.kezhongwenmingcheng = '' || '';
            formdataModel.lianxiren = '';
            formdataModel.shoujihao = '';
            formdataModel.dianhua = '';
            formdataModel.chuanzhen = '';
            formdataModel.email =  '';
            formdataModel.zhongwendizhi =  '';
            formdataModel.yingwendizhi =  '';
            formdataModel.shuilu =  '';
            formdataModel.hanshui =  0;
            formdataModel.kehaomingcheng =  ''
            this.$set(this, 'testFormData', formdataModel)
        }else if(index==1){ // 客户档案信息
            let resdata = await crudModuleFindApi("kehudangan", data.id)  
            let modeldata = resdata.data.module_info;
            let formdataModel = JSON.parse(JSON.stringify(this.$refs.preForm.formDataModel));
            formdataModel.kezhongwenmingcheng = modeldata.kezhongwenmingcheng || '';
            formdataModel.lianxiren = modeldata.lianxiren || '';
            formdataModel.shoujihao = modeldata.shoujihao || '';
            formdataModel.dianhua = modeldata.dianhua || '';
            formdataModel.chuanzhen = modeldata.chuanzhen || '';
            formdataModel.email = modeldata.email || '';
            formdataModel.zhongwendizhi = modeldata.zhongwendizhi || '';
            formdataModel.yingwendizhi = modeldata.yingwendizhi || '';
            formdataModel.shuilu = modeldata.shuilu || '';
            formdataModel.hanshui = modeldata.hanshui || 0;
            formdataModel.kehaomingcheng = modeldata.kehao || ''
            this.$set(this, 'testFormData', formdataModel)
        }else if(index == 2){ // 架类型
            // if(this.id && this.iscopy != 9){ // 当前为编辑-编辑不可改变销售单号
               
            // }else{
              let jialeixing = Number(data[0]);
              this.formSearch.jialeixing = [[jialeixing]]
              let resdata = await crudModuleListApi(this.keyName, this.formSearch)
              let resultdata = resdata.data.list;
              let xiaoshounum = 300000;
              if(resultdata.length > 0){
                let xiaoshoudanhao = resultdata[0].xiaoshoudanhao;
                let xiaoshounumbers = xiaoshoudanhao.match(/\d+/g)
                let isnums = 0;
                if(xiaoshounumbers.length > 0){
                  isnums = xiaoshounumbers.join("");
                }
                if(isnums < 300000){
                  xiaoshounum = 300000;
                }else{
                  xiaoshounum = Number(isnums) + 1;
                }
                console.log("xiaoshoudanhao:",xiaoshounumbers)
              }
              let formdataModel = JSON.parse(JSON.stringify(this.$refs.preForm.formDataModel));
              console.log("formdataModelB", formdataModel)
              this.handlerJialeixing(jialeixing, formdataModel, xiaoshounum)
            //}
        }
      },
      // 架类型事件
      handlerJialeixing(value, data, num=300000){
         data.jialeixing = value;
         switch(value) {
            case 1:
                data.xiaoshoudanhao = 'MF' + num;
                this.$set(this, 'testFormData', data)
                break;
            case 2:
                data.xiaoshoudanhao = 'AF' + num;
                this.$set(this, 'testFormData', data)
                break;
            case 3:
                data.xiaoshoudanhao = 'S-' + num;
                this.$set(this, 'testFormData', data)
                break;
            case 4:
                data.xiaoshoudanhao = 'IF' + num;
                this.$set(this, 'testFormData', data)
                break;
            case 5:
                data.xiaoshoudanhao = 'TF' + num;
                this.$set(this, 'testFormData', data)
                break;
            default:
                break;
         } 
      },
      // 保存数据
      saveFn() {
        this.$refs['preForm']
          .getFormData()
          .then((formData) => {
            this.formdatasubmit = formData;
            console.log("formdata", formData)
            if (this.id > 0 && this.iscopy !=1) { // 编辑
              // dengshunbo 2025-3-17
              
                if(this.keyName == 'xiaoshoudingdan'){
                    this.hadnlerdanghaolist(this.id);
                    let timea = setTimeout(()=>{
                      clearTimeout(timea)
                      this.upladData(this.id, formData)
                    }, 500)
                }else{
                  this.handlerSaveTabelFilter(this.id)
                  this.upladData(this.id, formData)
                }
              
            } else {
              // dengshunbo 2025-1-14 访客新增调后台接口
              if(this.keyName=="fangkeguanli"){
                this.formloading = true;
                if(formData.face_thumb.length == 0){
                   formData.face_thumb  = ''
                }
                let userinfoobj = JSON.parse(localStorage.getItem('userInfo'));
                formData.yaoqingrenxingming = userinfoobj.name
                if(formData.face_thumb){
                  let faceData = {face_thumb:  formData.face_thumb[0].url}
                   this.handlerFacialVerification(faceData, formData)
                }else{
                  if(formData.shouquanmenjinzu){
                      let meji = formData.shouquanmenjinzu.join(",")
                      formData.shouquanmenjinzu = meji
                  }else{
                      formData.shouquanmenjinzu = ''
                  }
                  this.savaData(formData)
                }
              }else{
                // 原代码
                this.formdatasubmit = formData;
                this.savaData(formData)
                
              }
            }
          })
          .catch((error) => {
            this.$message.error(error)
          })
      },
      // 调用关联表数据进行处理保存
      async handlerSaveTabelFilter(saveid){
        let formTabledata = this.$refs.wulidangan.formtable;
        let userinfo = JSON.parse(localStorage.getItem('userInfo'));
        for(let i=0;i<formTabledata.length;i++){
            // console.log("formTabledata[i]:"+i, formTabledata[i])
            if(formTabledata[i].istable){
              let tabledata2 = formTabledata[i].tableData;
              let addData = [];
              // 批量删除
              let deleteData = formTabledata[i].deleteData;
              if(deleteData.length > 0){
                await crudModuleBatchDelApi(formTabledata[i].value, {ids: deleteData}, true);
              }
              // 当前为编辑时调用
              console.log("this.iscopy", this.iscopy, this.id)
              if(this.iscopy==2 && this.id){ // 当前为编辑
                let formlinedatas = this.getArrayChanges(formTabledata[i].tableData, formTabledata[i].oldData);
               
                if(formlinedatas.added && formlinedatas.added.length > 0){ // 要添加的数据
                  await this.handerAddSaveForm(formTabledata[i], formlinedatas.added, userinfo.id, saveid)
                }
                if(formlinedatas.updated && formlinedatas.updated.length > 0){ // 要更新的数据
                  await this.handlerUpdateSaveForm(formTabledata[i], formlinedatas.updated)
                }     
              }else{ // 添加或复制添加时调用
                  if(tabledata2.length > 0){
                    console.log("this.keyName", this.keyName)
                    for(let j=0;j<tabledata2.length;j++){
                      let formdata2 = JSON.parse(JSON.stringify(tabledata2[j]))
                      formdata2.user_id = userinfo.id;
                      if(this.keyName=="wuliaoxinxi"){
                        // tabledata2[j].wuliaodanganid = saveid
                        formdata2.wuliaodanganid = saveid;
                          
                            if(formTabledata[i].value == 'kehuxinxi'){ // 客户档案客户信息表
                              let kehaolist = formTabledata[i].datadictList.kehuid;
                              let kehaoobj = this.handlerSTbase(tabledata2[j].kehao, kehaolist, 'kehao');
                              if(!formdata2.kehao){
                                formdata2.kehao = kehaoobj.kehao; // 客号
                              }
                              formdata2.kehuid = kehaoobj.id;
                            }
                          
                      }else if(this.keyName=="xiaoshoudingdan"){ // 销售订单
                        formdata2.xiaoshoudingdanid = saveid
                        if(tabledata2[j].wuliaodanganid){
                          formdata2.wuliaobianma = tabledata2[j].wuliaodanganid;
                        }
                        if(formdata2.pihe){
                           formdata2.pihe = ''
                        }
                        if(parentobj.value=='xiaoshoumingxi'){ // 销售明细表提交生成制造单号
                          let xiaoshoudanhao = this.formdatasubmit.xiaoshoudanhao;
                          formdata2.zhizaodanhao = xiaoshoudanhao + '-' + this.danghaoNumber + '.0-99';                
                        }
                      }
                      if(tabledata2[j].zhuangtai){ // 状态字典
                          let imdata = formTabledata[i].datadictList.zhuangtai;
                          for(let i=0;i<imdata.length;i++){
                            if(tabledata2[j].zhuangtai == imdata[i].value || tabledata2[j].zhuangtai == imdata[i].name ){
                              formdata2.zhuangtai = '/'+imdata[i].value+'/';
                            }
                          }
                      }

                      if(tabledata2[j].danwei){ // 单位字典
                          let imdata = formTabledata[i].datadictList.danwei;
                          for(let i=0;i<imdata.length;i++){
                            if(tabledata2[j].danwei == imdata[i].value || tabledata2[j].danwei == imdata[i].name ){
                              formdata2.danwei = '/' + imdata[i].value + '/';
                            }
                          }
                      }
                      if(tabledata2[j].bibie){ // 币别字典
                          let imdata = formTabledata[i].datadictList.bibie;
                          for(let i=0;i<imdata.length;i++){
                            if(tabledata2[j].bibie == imdata[i].value || tabledata2[j].bibie == imdata[i].name ){
                              formdata2.bibie = '/' + imdata[i].value + '/';
                            }
                          }
                      }
                      
                      delete formdata2.disabled;
                      delete formdata2.update_user_id;
                      delete formdata2.owner_user_id;
                      delete formdata2.created_at;
                      delete formdata2.updated_at
                      delete formdata2.owner_frame;
                      delete formdata2.create_user;
                      delete formdata2.update_user;
                      delete formdata2.is_share;
                      delete formdata2.owner_user;
                      delete formdata2.update_user;
                      delete formdata2.frame_id
                      delete formdata2.id
                      
                      addData.push(formdata2)
                      
                    }
                  }
                  console.log("addDATA", addData)
                  // 批量添加的数据处理(批量)
                  if(addData.length > 0){
                  
                    let objss = { table: formTabledata[i].value, data: encodeURI(JSON.stringify(addData))  }
                    await crudForminsertDataAllApi(objss)
                  }
              }
            }
        }
      },
      // 编辑-新增保存数据处理
      async handerAddSaveForm(parentobj, tabledata2, uid, saveid){
        let addData = []
        for(let j=0;j<tabledata2.length;j++){
            let formdata2 = JSON.parse(JSON.stringify(tabledata2[j]))
            formdata2.user_id = uid;
            if(this.keyName=="wuliaoxinxi"){
                formdata2.wuliaodanganid = saveid;   
                if(parentobj.value == 'kehuxinxi'){ // 客户档案客户信息表
                  let kehaolist = parentobj.datadictList.kehuid;
                  let kehaoobj = this.handlerSTbase(tabledata2[j].kehao, kehaolist, 'kehao');
                  if(!formdata2.kehao){
                    formdata2.kehao = kehaoobj.kehao; // 客号
                  }
                  formdata2.kehuid = kehaoobj.id;
                }
            }else if(this.keyName=="xiaoshoudingdan"){ // 销售订单
                formdata2.xiaoshoudingdanid = saveid;
                formdata2.wuliaobianma = tabledata2[j].wuliaodanganid;
                if(parentobj.value=='xiaoshoumingxi'){ // 销售明细表提交生成制造单号
                  let xiaoshoudanhao = this.formdatasubmit.xiaoshoudanhao;
                  formdata2.zhizaodanhao = xiaoshoudanhao + '-' + this.danghaoNumber + '.0-99';         
                }
            }
            if(tabledata2[j].zhuangtai){ // 状态字典
                let imdata = parentobj.datadictList.zhuangtai;
                for(let i=0;i<imdata.length;i++){
                  if(tabledata2[j].zhuangtai == imdata[i].value || tabledata2[j].zhuangtai == imdata[i].name ){
                    formdata2.zhuangtai = '/' + imdata[i].value + '/';
                  }
                }
            }
            if(tabledata2[j].danwei){ // 单位字典
                let imdata = parentobj.datadictList.danwei;
                for(let i=0;i<imdata.length;i++){
                  if(tabledata2[j].danwei == imdata[i].value || tabledata2[j].danwei == imdata[i].name ){
                    formdata2.danwei = '/' + imdata[i].value + '/';
                  }
                }
            }
            if(tabledata2[j].bibie){ // 币别字典
                let imdata = parentobj.datadictList.bibie;
                for(let i=0;i<imdata.length;i++){
                  if(tabledata2[j].bibie == imdata[i].value || tabledata2[j].bibie == imdata[i].name ){
                    formdata2.bibie = '/' + imdata[i].value + '/';
                  }
                }
            }
            delete formdata2.disabled;
            delete formdata2.update_user_id;
            delete formdata2.owner_user_id;
            delete formdata2.created_at;
            delete formdata2.updated_at
            delete formdata2.owner_frame;
            delete formdata2.create_user;
            delete formdata2.update_user;
            delete formdata2.is_share;
            delete formdata2.owner_user;
            delete formdata2.update_user;
            delete formdata2.frame_id
            delete formdata2.id
            addData.push(formdata2)  
        }
         console.log("addData", addData)
        let objss = { table: parentobj.value, data: encodeURI(JSON.stringify(addData))  }
        await crudForminsertDataAllApi(objss)

      },
      // 编辑-编辑修改保存数据处理
      async handlerUpdateSaveForm(parentobj, updata){
        for(let j=0;j<updata.length;j++){
            let tabledata2 = updata[j].new;
            let formdata3 = JSON.parse(JSON.stringify(tabledata2))
            if(tabledata2.zhuangtai){
              let imdata = parentobj.datadictList.zhuangtai;
              for(let i=0;i<imdata.length;i++){
                  if(tabledata2.zhuangtai == imdata[i].value || tabledata2.zhuangtai == imdata[i].name ){
                    formdata3.zhuangtai = '/'+imdata[i].value+'/';
                  }
              }
            }
            if(tabledata2.bibie){
              let imdata = parentobj.datadictList.bibie;
              for(let i=0;i<imdata.length;i++){
                  if(tabledata2.bibie == imdata[i].value || tabledata2.bibie == imdata[i].name ){
                    formdata3.bibie = '/'+imdata[i].value+'/';
                  }
              }
            }
            if(tabledata2.kehao){
              let imdata = parentobj.datadictList.kehuid;
              for(let i=0;i<imdata.length;i++){
                  if(tabledata2.kehao == imdata[i].kehao){
                    formdata3.kehuid = {id: imdata[i].id, name: imdata[i].kehao};
                  }
              }
            }

            if(tabledata2.danwei){
              let imdata = parentobj.datadictList.danwei;
              for(let i=0;i<imdata.length;i++){
                  if(tabledata2.danwei == imdata[i].value || tabledata2.danwei == imdata[i].name ){
                    formdata3.danwei = '/'+imdata[i].value+'/';
                  }
              }
            }
            if(this.keyName == 'xiaoshoudingdan'){
              formdata3.wuliaodanganid = Number(tabledata2.wuliaodanganid);
              if(tabledata2.wuliaobianma){
                formdata3.wuliaobianma = {id: formdata3.wuliaodanganid, name: tabledata2.wuliaobianma};
              }
            }
            console.log("formdata3", formdata3)
           await crudModuleUpdateApi(parentobj.value, tabledata2.id,formdata3, true)
        }
      },
      // 数据比较(新数据和旧数据进行比较，返回新增、更新和删除的项数组)
      getArrayChanges(newArray, oldArray, idKey = 'id') {
          const changes = {
            added: [],
            updated: [],
            removed: []
          };
          // 检查新增和更新的项
          newArray.forEach(newItem => {
            const oldItem = oldArray.find(old => old[idKey] === newItem[idKey]);
            if (!oldItem) {
              changes.added.push(newItem);
            } else if (!_.isEqual(newItem, oldItem)) {
              changes.updated.push({ old: oldItem, new: newItem });
            }
          });
          // 检查删除的项
          oldArray.forEach(oldItem => {
            if (!newArray.find(newItem => newItem[idKey] === oldItem[idKey])) {
              changes.removed.push(oldItem);
            }
          });

          return changes;
      },
      handlerSTbase(val, data, filed){
         if(val){
            for(let i=0;i<data.length;i++){
               if(val == data[i][filed]){
                   return data[i] || ''
               }
            }
            return ''
         }else{
            return ''
         }
      },
      // 数组比较
      arraysAreEqual(arr1, arr2) {
        return JSON.stringify(arr1) === JSON.stringify(arr2);
      },
      // 关联物料档案实体表保存接口
      handlersaveData(keyName, data){
        crudModuleSaveDataApi(keyName, data, true)
          .then((res) => {
            if (res.status == 200) {
              
            }
          })
          .catch((err) => {
            this.loading = false
          })
      },
      // 关联物料档案实体表删除接口
      handlerDeleteData(keyName, data){
        crudModuleBatchDelApi(keyName, data, true)
          .then((res) => {
            if (res.status == 200) {
              
            }
          })
          .catch((err) => {
            this.loading = false
          })
      },
      // 实体列表新增保存
      async savaData(data) {
        this.loading = true
        if (this.crud) {
          data.crud_id = this.crud.crud_id
          data.crud_value = this.crud.crud_value
        }
       
       
          // 原代码
          crudModuleSaveDataApi(this.keyName, data)
          .then((res) => {
            if (res.status == 200) {
              let saveid = res.data.id;
              console.log("this.keyName", this.keyName)
              if(this.keyName == 'xiaoshoudingdan'){
                   this.hadnlerdanghaolist(saveid);
              }else{
                 this.handlerSaveTabelFilter(saveid)
              }
              this.handleClose()
              
              this.$emit('getList')

              this.isSubmit = 0;
            }
            this.loading = false
          })
          .catch((err) => {
            this.loading = false
          })
        
      },
      hadnlerdanghaolist(saveid){
        let formdataA ={page: 1, limit:20,is_field_all: 1,is_system: 1, order_by: {}, scope_frame:'all', show_search_type: '0', view_search: [], view_search_boolean:'', xiaoshoudingdanid: saveid}
        crudModuleListApi('xiaoshoumingxi', formdataA).then(res=>{
           this.danghaoNumber = 10;
           if(res.data.list.length > 0){
              let rlength = res.data.list.length;
              this.danghaoNumber = (rlength + 1) * 10
           }
           this.handlerSaveTabelFilter(saveid)
        }).catch(err=>{
          this.handlerSaveTabelFilter(saveid)
        })

        
      },
      // dengshunbo 2025-1-14 访客新增调后台接口
      handlerFacialVerification(faceobj, formdata, id=0){
        FacialVerificationApi(faceobj).then((res)=>{
          if(res.data.code==200){
             if(res.data.data){
                if(formdata.shouquanmenjinzu){
                    let meji = formdata.shouquanmenjinzu.join(",")
                    formdata.shouquanmenjinzu = meji
                }else{
                  formdata.shouquanmenjinzu = ''
                }
                if(id==0){
                  this.savaData(formdata)
                }else{
                  this.upladData(this.id, formdata)
                }
             }else{
                this.$message.error("实拍头像识别失败,请检查头像是否清晰或正确")
             }
          }else{
            this.$message.error(res.data.message)
          }
        }).catch((err)=>{
          if(err.data.code==200){
             if(err.data.data){
                if(formdata.shouquanmenjinzu){
                    let meji = formdata.shouquanmenjinzu.join(",")
                    formdata.shouquanmenjinzu = meji
                }else{
                  formdata.shouquanmenjinzu = ''
                }
                if(id==0){
                  this.savaData(formdata)
                }else{
                  this.upladData(this.id, formdata)
                }
             }else{
                this.formloading = false;
                this.$message.error("实拍头像识别失败,请检查头像是否清晰或正确")
             }
          }else{
            this.formloading = false;
            this.$message.error(err.data.message)
          }
        })
      },
    
     
     
      // end
      // 实体列表更新保存
      upladData(id, data) {
        this.loading = true
        if (this.crud) {
          data.crud_id = this.crud.crud_id
          data.crud_value = this.crud.crud_value
        }
        
        // 原代码
        crudModuleUpdateApi(this.keyName, id, data)
          .then((res) => {
            if (res.status == 200) {
              this.handleClose()
              this.$emit('getList')
              this.isSubmit = 0;
              
            }
            this.loading = false
          })
          .catch((err) => {
            this.loading = false
          })
        
      },
  
      handleClose() {
        // this.$refs['preForm'].resetForm()
        this.drawer = false
        // this.id = 0
        this.isSubmit = 0;
      },
      // dengshunbo 2025-1-14 时间戳转换
      hadnlerFilterReturn(time=''){
        let rtime = ''
        if(time){
          rtime = new Date(time).getTime();
        }else{
          rtime = new Date().getTime();
        }
        return rtime;
      },

     
      
    }
  }
  </script>
  <style scoped lang="scss">
  /deep/.el-drawer__body {
    padding: 10px 20px 50px 20px;
  }
  .p10 {
    width: 100%;
    padding: 0 10px;
  }
  .fixnew{
    position: absolute;
    top:10px;right:70px;
  }
  /deep/ .el-tabs__header .el-tabs__item{
    line-height:40px!important;
  }
  /deep/ .el-upload--picture-card{
    width:100px;height:100px;line-height: 100px;
  }
  </style>
  